home *** CD-ROM | disk | FTP | other *** search
- Path: news.bdsi.com!bdsi
- From: sonia_mangat@bdsi.com (Sonia Mangat)
- Newsgroups: comp.lang.c++
- Subject: Overloaded Virtual functions
- Date: Tue, 27 Feb 1996 10:34:46 GMT
- Organization: Beechwood Data Systems
- Message-ID: <4gv8to$7dm@news.bdsi.com>
- Reply-To: sonia_mangat@bdsi.com (Sonia Mangat)
- NNTP-Posting-Host: 204.107.74.107
-
- Hi everybody,
- I have a question on overloaded virtual functions. I have included a
- program that has a parent class with overloaded virtual functions.
- I have also attached the compilation error I get.
-
- The ways I can think of correcting this problem are
- --> Declare the other prototype in the class B and make it call it's
- parent's function.
- --> Give different names for the virtual function.
-
- I don't like both these options. Is there any other way to solve this
- problem?
-
- Please respond to : vidhya@bdsi.com
-
- Thanks in advance
- vidhya
-
-
- ***** Program: a.C ***********
-
- 1: #include <iostream.h>
-
- 2: class T
- 3: {
- 4: public:
- 5: };
-
-
- 6: class A
- 7: {
- 8: public:
- 9: virtual void print(int) { cout << "A int" << endl;}
- 10: virtual void print(const T&) { cout << "A char" << endl;
- }
- 11: };
-
- 12: class B : public A
- 13: {
- 14: public:
- 15: virtual void print(int) { cout << "B int" << endl;}
- 16: };
-
-
- 17: main()
- 18: {
-
- 18: {
- 19: T p;
- 20: B b;
- 21: b.print(p);
- 22: return 0;
- 23: }
-
-
- ****** Compilation error ********
-
- "a.C", line 20.30: 1540-293: (W) "B::print(int)" hides the virtual
- function "A::
- print(const T&)".
- "a.C", line 28.17: 1540-055: (S) "T" cannot be converted to "int".
- "a.C", line 28.17: 1540-306: (I) The previous message applies to
- argument 1 of function "B::print(int)".
-
-